// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 

package com.feiyue;

import android.app.Activity;
import android.content.*;
import android.os.Bundle;
import android.os.Handler;
import android.view.*;
import android.widget.*;

import com.feiyue.basic.reader.util.CustomToast;
import com.feiyue.basic.server.db.BookCollectDBHandler;
import com.feiyue.basic.server.net.NovelInfo;
import com.feiyue.basic.server.parser.Book;
import com.feiyue.helper.BookListAdapter;
import com.umeng.analytics.MobclickAgent;

import java.util.*;

// Referenced classes of package com.feiyue:
//          BookBriefActivity

public class BookRankListActivity extends Activity
    implements android.widget.AbsListView.OnScrollListener, android.view.View.OnTouchListener, android.view.GestureDetector.OnGestureListener
{
    public class MessageReceiver extends BroadcastReceiver
    {

        public void onReceive(Context context1, Intent intent)
        {
            BookCollectDBHandler bookcollectdbhandler;
			try {
				bookcollectdbhandler = new BookCollectDBHandler(context1);
				listItemAdapter.setCollectbooklist(bookcollectdbhandler.getBookList(context1));
	            bookcollectdbhandler.destroy();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            
        }
    }

    private class MyThread extends Thread
    {

        public void run()
        {
            if (hasmore)
            {
                if (flag.equals("totalrank"))
                    localbooklist = NovelInfo.getNewestBookList(context, NovelInfo.getUrl2hotBooklist(booklist.size(), 10));
                else
                if (flag.equals("weekrank"))
                    localbooklist = NovelInfo.getNewestBookList(context, NovelInfo.getUrl2weekhotBooklist(booklist.size(), 10));
                else
                if (flag.equals("monthrank"))
                    localbooklist = NovelInfo.getNewestBookList(context, NovelInfo.getUrl2monthhotBooklist(booklist.size(), 10));
                else
                if (flag.equals("boyrank"))
                    localbooklist = NovelInfo.getNewestBookList(context, NovelInfo.getUrl2boyhotBooklist(booklist.size(), 10));
                else
                if (flag.equals("girlrank"))
                    localbooklist = NovelInfo.getNewestBookList(context, NovelInfo.getUrl2girlhotBooklist(booklist.size(), 10));
                if (localbooklist != null && localbooklist.size() != 0)
                {
                    myrunnable.setisload(true);
                } else
                {
                    hasmore = false;
                    myrunnable.setisvisible(true);
                }
                handler.post(myrunnable);
            } else
            {
                myrunnable.setisvisible(true);
                handler.post(myrunnable);
            }
            super.run();
        }
    }

    private class Myrunnable
        implements Runnable
    {

        public boolean isload = false;
        public boolean isvisible = false;

        private void reset()
        {
            isload = false;
            isvisible = false;
        }

        public void run()
        {
            if (isload)
                load();
            if (isvisible)
            {
                (new CustomToast(context)).show("已显示全部内容，请等待更新", 300);
                morebooks.setVisibility(8);
            }
            reset();
            thread2getnewbookisrunning = false;
        }

        public void setisload(boolean flag1)
        {
            isload = flag1;
        }

        public void setisvisible(boolean flag1)
        {
            isvisible = flag1;
        }
    }


    private List booklist;
    private Context context;
    private String flag;
    private ImageView goback;
    private Handler handler;
    private boolean hasmore;
    private int lastbottom;
    private ListView list;
    private ArrayList listItem;
    private BookListAdapter listItemAdapter;
    private LinearLayout list_linear;
    public List localbooklist;
    private GestureDetector mGestureDetector;
    private MessageReceiver messageReceiver;
    private int minVelocity;
    private LinearLayout morebooks;
    private Myrunnable myrunnable;
    private boolean thread2getnewbookisrunning;
    private int verticalMinDistance;

    public BookRankListActivity()
    {
        thread2getnewbookisrunning = false;
        hasmore = true;
        verticalMinDistance = 200;
        minVelocity = 150;
    }

    public boolean dispatchTouchEvent(MotionEvent motionevent)
    {
        boolean flag1;
        if (!mGestureDetector.onTouchEvent(motionevent))
            flag1 = super.dispatchTouchEvent(motionevent);
        else
            flag1 = true;
        return flag1;
    }

    public void load()
    {
        booklist.addAll(localbooklist);
        int i = localbooklist.size();
        int j = 0;
        do
        {
            if (j >= i)
            {
                listItemAdapter.notifyDataSetChanged();
                morebooks.setVisibility(8);
                list_linear.setVisibility(0);
                return;
            }
            HashMap hashmap = new HashMap();
            hashmap.put("ItemTile", ((Book)localbooklist.get(j)).getName());
            hashmap.put("ItemAuthor", (new StringBuilder("作者:")).append(((Book)localbooklist.get(j)).getAuthor()).toString());
            hashmap.put("ItemIntroduction", (new StringBuilder("介绍:")).append(((Book)localbooklist.get(j)).getIntroduction()).toString());
            listItem.add(hashmap);
            j++;
        } while (true);
    }

    public void onCreate(Bundle bundle)
    {
        TextView textview;
        super.onCreate(bundle);
        setContentView(0x7f030002);
        mGestureDetector = new GestureDetector(this);
        LinearLayout linearlayout = (LinearLayout)findViewById(0x7f060024);
        linearlayout.setOnTouchListener(this);
        linearlayout.setLongClickable(true);
        context = getApplicationContext();
        flag = getIntent().getExtras().getString("flag");
        morebooks = (LinearLayout)findViewById(0x7f06002a);
        morebooks.setVisibility(8);
        list_linear = (LinearLayout)findViewById(0x7f060028);
        textview = (TextView)findViewById(0x7f060027);
        if (!flag.equals("weekrank")) {
        	if (flag.equals("monthrank"))
                textview.setText("月排行");
            else
            if (flag.equals("totalrank"))
                textview.setText("总排行");
            else
            if (flag.equals("boyrank"))
                textview.setText("男生排行");
            else
            if (flag.equals("girlrank"))
                textview.setText("女生排行");
        } else {
        	textview.setText("周排行");
        }
        
        
        list = (ListView)findViewById(0x7f060029);
        list.setOnScrollListener(this);
        booklist = new ArrayList();
        localbooklist = new ArrayList();
        listItem = new ArrayList();
        ArrayList arraylist = listItem;
        String as[] = new String[3];
        as[0] = "ItemTile";
        as[1] = "ItemAuthor";
        as[2] = "ItemIntroduction";
        int ai[] = new int[3];
        ai[0] = 0x7f06002f;
        ai[1] = 0x7f060030;
        ai[2] = 0x7f060031;
        listItemAdapter = new BookListAdapter(this, arraylist, 0x7f030003, as, ai, booklist);
        list.setAdapter(listItemAdapter);
        list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView adapterview, View view, int i, long l)
            {
                setTitle((new StringBuilder("点击第")).append(i).append("个项目").toString());
                String s = ((Book)booklist.get(i)).getName();
                int j = ((Book)booklist.get(i)).getId();
                int k = ((Book)booklist.get(i)).getCoverid();
                String s1 = ((Book)booklist.get(i)).getCoverAddr();
                int i1 = ((Book)booklist.get(i)).getdlstate();
                String s2 = ((Book)booklist.get(i)).getAuthor();
                String s3 = ((Book)booklist.get(i)).getIntroduction();
                String s4 = ((Book)booklist.get(i)).getIssuestate();
                Intent intent = new Intent(getApplicationContext(), BookBriefActivity.class);
                intent.putExtra("categoryname", flag);
                intent.putExtra("bookname", s);
                intent.putExtra("bookid", j);
                intent.putExtra("author", s2);
                intent.putExtra("introduction", s3);
                intent.putExtra("issuestate", s4);
                intent.putExtra("coverid", k);
                intent.putExtra("coverAddr", s1);
                intent.putExtra("dlstate", i1);
                startActivity(intent);
            }
        });
        myrunnable = new Myrunnable();
        handler = new Handler();
        morebooks.setVisibility(0);
        list_linear.setVisibility(8);
        thread2getnewbookisrunning = true;
        (new MyThread()).start();
        messageReceiver = new MessageReceiver();
        IntentFilter intentfilter = new IntentFilter("MESSAGERECEIVER_BOOKID");
        registerReceiver(messageReceiver, intentfilter);
        goback = (ImageView)findViewById(0x7f060026);
        goback.setOnClickListener(new android.view.View.OnClickListener() {

            public void onClick(View view)
            {
                finish();
                overridePendingTransition(0x7f04000a, 0x7f04000d);
            }
        });
    }

    protected void onDestroy()
    {
        unregisterReceiver(messageReceiver);
        super.onDestroy();
    }

    public boolean onDown(MotionEvent motionevent)
    {
        return false;
    }

    public boolean onFling(MotionEvent motionevent, MotionEvent motionevent1, float f, float f1)
    {
        boolean flag1 = true;
        float f2 = Math.abs(motionevent.getX() - motionevent1.getX()) / Math.abs(motionevent.getY() - motionevent1.getY());
        if (motionevent.getX() - motionevent1.getX() > 0.0F && (double)f2 - 2.5D > 0.0D)
        {
            finish();
            overridePendingTransition(0x7f04000b, 0x7f04000c);
        } else
        if (motionevent.getX() - motionevent1.getX() < 0.0F && (double)f2 - 2.5D > 0.0D)
        {
            finish();
            overridePendingTransition(0x7f04000a, 0x7f04000d);
        } else
        {
            flag1 = false;
        }
        return flag1;
    }

    public boolean onKeyDown(int i, KeyEvent keyevent)
    {
        boolean flag1;
        if (i == 4)
        {
            finish();
            overridePendingTransition(0x7f04000a, 0x7f04000d);
            flag1 = true;
        } else
        {
            flag1 = super.onKeyDown(i, keyevent);
        }
        return flag1;
    }

    public void onLongPress(MotionEvent motionevent)
    {
    }

    protected void onPause()
    {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    protected void onResume()
    {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    public void onScroll(AbsListView abslistview, int i, int j, int k)
    {
        if (lastbottom != i + j) {
        	lastbottom = i + j;
            if (i + j == k && k != 0)
            {
                morebooks.setVisibility(0);
                if (!thread2getnewbookisrunning)
                {
                    thread2getnewbookisrunning = true;
                    (new MyThread()).start();
                }
            } else
            {
                morebooks.setVisibility(8);
            }
        }
    }

    public boolean onScroll(MotionEvent motionevent, MotionEvent motionevent1, float f, float f1)
    {
        return false;
    }

    public void onScrollStateChanged(AbsListView abslistview, int i)
    {
    }

    public void onShowPress(MotionEvent motionevent)
    {
    }

    public boolean onSingleTapUp(MotionEvent motionevent)
    {
        return false;
    }

    public boolean onTouch(View view, MotionEvent motionevent)
    {
        return mGestureDetector.onTouchEvent(motionevent);
    }

}